from flask_sqlalchemy import SQLAlchemy
from flask import Flask
from flask_wtf.csrf import CSRFProtect
import config
import os
from Encryption_and_decryption import get_hash_from_str
from flask_mail import Mail

# 创建 SQLAlchemy 数据库实例
db = SQLAlchemy()
mail = Mail()

def create_app():
    
    app = Flask(__name__)
    # 开启CSRF保护
    CSRFProtect(app)

    app.config.from_object(config)
    db.init_app(app)
    mail.init_app(app)

    # with app.app_context():
    #     db.drop_all()
    #     db.create_all()

    return app